The purpose of a logger is to be able to do so under a certain range (a class or a package), and the output of the log is different from the way the log is exported elsewhere.
log4j.properties
configuration Logger, the purpose is to control a certain range of log output, such as the child logger here is to control the Cn.server.test packet under the log
logger, and the last is the log information.In this program, the log4j is initialized with a basic configuration class Basicconfigurator provided by log4j. But it's not usually done when it's actually used, because it's a bit of a "hard" code. In the future, if you want to modify the configuration of the log4j, you ne
OK, now we carefully study the configuration of the next logger, the related configuration extension.
Log4j has three main components: loggers (recorder), appenders (output source), and layouts (layout). Among them, logger is responsible for logging, Appender responsible for the output to where, layout is responsible for what format output, output which addition
(Conversion) log4j: WARN No appenders cocould be found for logger solution, log4jappenders
When using Log4j, we always see:
1 log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).2 log4j:WARN Please initialize the log4j system properly.
Th
log4j: Specify the output level of a logger individually--
Generally for production systems, log levels are adjusted to info to avoid excessive output logs.But at some point, you need to keep track of specific issues, so you have to turn on the debug log.But if you open the Log4j.rootlogger, the information you need will be submerged in the log ocean.At this point, you need to specify that a log level of
=falseLog4j.appender.b.file = D:/abc/b.logLog4j.appender.b.append = TrueLog4j.appender.b.datepattern=yyyy-wwLog4j.appender.b.threshold = INFOLog4j.appender.b.layout = Org.apache.log4j.PatternLayoutLog4j.appender.b.layout.conversionpattern =%5p%10d{yyyy-mm-dd HH:mm:ss} {%c:%l}%m%nDoes the code use logger logger = Loggerfactory.getlogger ("B") to output the log? The answer is in the negative.Because only log
Why does I see a warning about "No Appenders found for logger" and "please configure log4j properly"? This occurs when the default configuration files Log4j.properties The and log4j.xml can not is found and the application performs no explicit configuration. Log4j uses thread.getcontextclassloader (). GetResource () to locate the default configuration fil
In spring web projects, this kind of prompt often appears when Tomcat is started: Reference log4j: warn no appenders cocould be found for logger (Org. springframework. Web. Context. contextloader ).Log4j: Warn please initialize the log4j system properly.
There are a lot of solutions available on the Internet, this prom
The version used here is for Log4j-1.2.15,jar resources to get the download. first, the introduction
During the normal development process, sometimes do not want to print all the logs to the same log file, in addition to the Java Engineering Integration log4j 1.x posting introduction of the use of a logger, Configuring multiple Appender Log4j.appender.d.threshold
With log4j, you can easily process logs in your project-control the destination of the Log information output (console, file, GUI component, or NT Event recorder), control the output format of each log (htmllayout layout format, patternlayout layout format, Simplelayout layout format or ttcclayout), controls the level of output log information (debug level, info level, warn level, error level, or fatal level), and so on. Here's a simple
steps:
Create a new Java project and import the log4j jar package;
Create the Log4j.properties profile and set it in the SRC directory;1 # Set the global output level2Log4j.rootlogger=Error,stdout,file3 4 # Output logs above the error level to the console5log4j.appender.stdout=Org.apache.log4j.ConsoleAppender6log4j.appender.stdout.target=System.out7log4j.appender.stdout.layout=Org.apache.log4j.PatternLayout8Log4j.appender.stdout.layout.conversio
Example of how MyBatis3 outputs SQL using log4j on the console, mybatis3log4j
Why do I need to output SQL statements on the console?
Of course, it is convenient for development and debugging.
If a database-related operation encounters a problem, we can quickly troubleshoot the problem based on the output SQL statement.
Output Information:
[Org. mybatis. spring. SqlSessionUtils]-Creating a new SqlSession[O
: log4j.apache.mylogger=warn-Log4j.apache.mylogger.mysonlogger=,file In the above code, Mysonlogger is the subclass logger component of MyLogger. 6. Specify the log level in the package unit Log4j.logger.com.neareast =debugLog4j.logger.org.apache.struts=warnSpecifies that all classes under the Com.neareast package are rated as Debug.Specifies that all classes under the Struts package are rated warn. 7. Basic Use Method usually there are two ways to us
First need to download log4j package, the current use of the most is still log4j 1.2, although Log4j 2 has been released, Log4j 1.2: http://logging.apache.org/log4j/1.2/download.htmlDownload complete decompression, log4j is a very
The website is about to be released. To track some logs, you need to use log4j. So I studied the configuration of log4j.
First, paste a configuration source file log4j. properties.
log4j.rootLogger=DEBUG, CONSOLE, FILE## for consolelog4j.appender.CONSOLE=org.apache.log4j.ConsoleAppenderlog4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayoutlog4j.appender.CO
rootLogger level. Under this premise, the logger levels take effect based on their own settings.
MyBatis Study Notes series I: download and install ant
Prepare for MyBatis Study Notes Series II: ant getting started
MyBatis learning notes: MyBatis getting started
MyBatis Study Notes Series II: Example of adding, deleting, and modifying MyBatis
MyBatis Study Notes Series 3: association examples of MyBatis
M
I have not written examples in the log4j usage notes. In this article, I will write a complete application instance of log4j.
In the log4j usage notes, we already know that the same log information can be output to multiple output destinations at the same time. In the following example, I will demonstrate how to output
to console. The next two lines are set log format, usually you copy it.
In the actual project development, it is likely to encounter the quoted package log4j to log, such as Hibernate. So here you can easily control how the packet logs. For example, add a line to the above configuration file:
Log4j.logger.org.hibernate=fatal
Then all the classes below the Org.hibernate package will show very little inform
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.